class Position {

  static mapping = {
    table 'position_table'
    cache true
  }  

  String name
  String description
  String location
  int requires = 1
  Date startDate
  Date endDate
  long eventId

  static belongsTo = Event
  static hasMany = [volunteers: UserAccount]

  static transients = ["eventId"]

  static constraints = {
    name(maxSize: 40, nullable: false, blank: false)
    description(maxSize: 250, nullable: true)
    location()
    requires(min: 1)
    startDate(nullable: true)
    endDate(nullable: true)
    volunteers()
  }

  boolean equals(o) {
    if (this.is(o)) return true;

    if (!o || getClass() != o.class) return false;

    Position position = (Position) o;

    if (requires != position.requires) return false;
    if (description ? !description.equals(position.description) : position.description != null) return false;
    if (endDate ? !endDate.equals(position.endDate) : position.endDate != null) return false;
    if (location ? !location.equals(position.location) : position.location != null) return false;
    if (name ? !name.equals(position.name) : position.name != null) return false;
    if (startDate ? !startDate.equals(position.startDate) : position.startDate != null) return false;

    return true;
  }

  int hashCode() {
    int result;

    result = (name ? name.hashCode() : 0);
    result = 31 * result + (description ? description.hashCode() : 0);
    result = 31 * result + (location ? location.hashCode() : 0);
    result = 31 * result + requires;
    result = 31 * result + (startDate ? startDate.hashCode() : 0);
    result = 31 * result + (endDate ? endDate.hashCode() : 0);
    return result;
  }

}
